package com.ygqh.baby.controller.admin;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ygqh.baby.ao.Message;
import com.ygqh.baby.ao.QueryInfo;
import com.ygqh.baby.ao.ResultSet;
import com.ygqh.baby.po.YgChannelCategory;
import com.ygqh.baby.service.YgChannelService;
import com.ygqh.baby.utils.JsonUtils;


@Controller
@RequestMapping("/admin/channelcategory")
public class ChannelCategoryController extends BaseController<Object, java.lang.Long> {

	@Autowired
	private YgChannelService ygChannelService;
	
	@RequestMapping("searchChanelCategory")
	@ResponseBody
	public Map<String, Object> searchCategory(String q, QueryInfo queryInfo){
		ResultSet<YgChannelCategory> resultSet = ygChannelService.searchChannelCategory(queryInfo, q);
	   return resultSet.toDatatables(null);
	}
	
	@RequestMapping("saveChanelCategory")
	@ResponseBody
	public Message saveCategory(String category) {
		YgChannelCategory yyCategory=JsonUtils.toObject(category, YgChannelCategory.class);		
		yyCategory.setCreateBy(getSession().getTrueName());
		yyCategory.setCreateTime(new Date());
		
		if(yyCategory.getId()!=null)
		 return ygChannelService.updateChannelCategory(yyCategory)==1?SUCCESS_MESSAGE:ERROR_MESSAGE;
	   return ygChannelService.saveChannelCategory(yyCategory)==1?SUCCESS_MESSAGE:ERROR_MESSAGE;
	
	}
	@RequestMapping("searchChannelCategoryList")
	@ResponseBody
	public List<YgChannelCategory> searchCategoryList(){		
		return ygChannelService.findAllChannelCategory();		
		
	}
	
}
